<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>

<form action="<?php echo url_for('itemescotizaciones/'.($form->getObject()->isNew() ? 'create' : 'update').(!$form->getObject()->isNew() ? '?id='.$form->getObject()->getId() : '')) ?>" method="post" <?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>
<?php if (!$form->getObject()->isNew()): ?>
<input type="hidden" name="sf_method" value="put" />
<?php endif; ?>
  <table>
    <tfoot>
      <tr>
        <td colspan="2">
          <?php echo $form->renderHiddenFields(false) ?>
          &nbsp;<a href="<?php echo url_for('itemescotizaciones/index') ?>">Back to list</a>
          <?php if (!$form->getObject()->isNew()): ?>
            &nbsp;<?php echo link_to('Delete', 'itemescotizaciones/delete?id='.$form->getObject()->getId(), array('method' => 'delete', 'confirm' => 'Are you sure?')) ?>
          <?php endif; ?>
          <input type="submit" value="Save" />
        </td>
      </tr>
    </tfoot>
    <tbody>
      <?php echo $form->renderGlobalErrors() ?>
      <tr>
        <th><?php echo $form['articulo_id']->renderLabel() ?></th>
        <td>
          <?php echo $form['articulo_id']->renderError() ?>
          <?php echo $form['articulo_id'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['cotizacion_id']->renderLabel() ?></th>
        <td>
          <?php echo $form['cotizacion_id']->renderError() ?>
          <?php echo $form['cotizacion_id'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['cantidad']->renderLabel() ?></th>
        <td>
          <?php echo $form['cantidad']->renderError() ?>
          <?php echo $form['cantidad'] ?>
        </td>
      </tr>
      <tr>
        <th><?php echo $form['observacion']->renderLabel() ?></th>
        <td>
          <?php echo $form['observacion']->renderError() ?>
          <?php echo $form['observacion'] ?>
        </td>
      </tr>
      
      <tr>
        <th>Detalles:</th>
        <td>
          <ul id="contenedor">
          
                    <?php if ($form->getObject()->isNew()): ?>
          <script type="text/javascript">newfieldscount = 1;</script>
          <li>
            <?php echo $form['new'][0]['proveedor_id']->renderLabel() ?>  
            <?php echo $form['new'][0]['proveedor_id']->renderError() ?>
            <?php echo $form['new'][0]['proveedor_id'] ?>
            -
            <?php echo $form['new'][0]['precio']->renderLabel() ?>  
            <?php echo $form['new'][0]['precio']->renderError() ?>
            <?php echo $form['new'][0]['precio'] ?>
          </li>
          <?php endif ?>
          
          <?php $i=0; ?>
          
            <?php foreach ($form['DetalleItemCotizacionNacional'] as $detalle):?>
            <li>
              <?php echo $detalle['proveedor_id']->renderLabel() ?>  
              <?php echo $detalle['proveedor_id']->renderError() ?>
              <?php echo $detalle['proveedor_id'] ?>
              -
              <?php echo $detalle['precio']->renderLabel() ?>  
              <?php echo $detalle['precio']->renderError() ?>
              <?php echo $detalle['precio'] ?>

              <?php $data = $form->getObject()->getDetalleItemCotizacionNacional() ?>
              
              <?php 
                echo link_to('eliminar', 'detallescotizaciones/delete?id='.$data[$i], array('method' => 'delete', 'confirm' => 'Estás seguro de eliminar el detalle?')); 
                $i++;
              ?>
            
            </li>
            <?php endforeach ?>
          </ul>
          <a id="addoccurrence" href="#">Agregar Detalle</a>
        </td>
      </tr>
      
    </tbody>
  </table>
</form>
